package com.zb.order.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.order.service.ConWorkModuleService;
import com.zb.result.Result;
import com.zb.service.ZjWorkModuleService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkModuleSelectVo;
import com.zb.vo.WorkModuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.el.parser.Token;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工单模块表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-13
 */
@Api(tags = "工单模块类接口")
@RestController
@RequestMapping("/work/module")
public class ZjWorkModuleController {
    @Resource
    private ConWorkModuleService conWorkModuleService;
    @Resource
    private ZjWorkModuleService workModuleService;

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "工单管理-工单设置-工单模块 - 新增或修改工单模块")
    @ApiOperation("新增或修改工单模块")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid WorkModuleVo workModuleVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workModuleService.save(custAccId, workModuleVo);
        return Result.success(null == workModuleVo.getId()? "新增模块成功" : "修改模块成功");
    }

    @ApiOperation("获取工单模块列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody WorkModuleSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取工单模块列表成功").data(workModuleService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据模块ID获取工单模块详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "模块ID", required = true) Long id) {
        return Result.success("获取工单模块详情成功").data("row", workModuleService.getDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单模块 - 根据模块ID批量启用或禁用模块")
    @ApiOperation("根据模块ID批量启用或禁用模块")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "模块状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "模块ID集合", required = true) List<Long> idList) {
        workModuleService.updateDisabledBatchById(idList, status);
        return Result.success(status? "禁用模块成功" : "启用模块成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.DELETE, remark = "工单管理-工单设置-工单模块 - 根据模块ID批量删除模块")
    @ApiOperation("根据模块ID批量删除模块")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "模块ID集合", required = true) List<Long> idList) {
        conWorkModuleService.deleteBatchById(idList);
        return Result.success("删除模块成功");
    }



}
